/**
 * 确认密码校验
 * @param {*} form
 */
export const useConfirmPasswordValidator = (form) => {
  console.log(form, 'form');
  const validateConfirmPassword = (rule, value, callback) => {
    console.log(value, form, 'value');

    if (value === '') {
      callback(new Error('请再次输入密码'));
    } else if (value !== form.password) {
      callback(new Error('两次输入密码不一致'));
    } else {
      callback();
    }
  };
  return [
    { required: true, message: '请确认密码', trigger: 'blur' },
    { validator: validateConfirmPassword, trigger: 'blur' },
  ];
};

/**
 * 邮箱校验
 * @param {*} value
 */
export const validateEmail = (rule, value, callback) => {
  // 简单的邮箱校验正则表达式
  const emailRegex = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
  if (!emailRegex.test(value)) {
    callback(new Error('请输入有效的邮箱地址'));
  } else {
    callback();
  }
};
